package jxerializeml.examples.game_config.beans;

import java.io.IOException;

import jxerializeml.JXerializeML;
import jxerializeml.clues.classes.InvokeClassListeners;
import jxerializeml.clues.fields.SetComment;
import jxerializeml.clues.structures.ClassListener;
import jxerializeml.errors.JXerializeMLError;
import jxerializeml.handling.ReadWriteListener;
import jxerializeml.xml.transformers.DefaultTransformers;

@InvokeClassListeners(methods = {
	ClassListener.PRE_SERIALIZE, ClassListener.PRE_DESERIALIZE,
	ClassListener.POST_SERIALIZE, ClassListener.POST_DESERIALIZE
})
public class ConfigurationBean implements ReadWriteListener {
	@SetComment(description = "Sound settings")
	private ConfigurationSoundsBean sounds = new ConfigurationSoundsBean();
	
	@SetComment(description = "Video settings")
	private ConfigurationGraphicsBean graphics = new ConfigurationGraphicsBean();
	
	public static ConfigurationBean load(String filename) {
		try {
			return new JXerializeML<ConfigurationBean>().readObject(filename, DefaultTransformers.TECHNICAL);
		} catch (Exception e) {
			return new ConfigurationBean();
		}
	}
	
	public void save(String filename) throws JXerializeMLError, IOException {
		new JXerializeML<ConfigurationBean>().writeObject(this, filename, DefaultTransformers.TECHNICAL);
	}

	@Override public void postdeserialize() {}
	@Override public void postserialize() {}
	@Override public void predeserialize() {}
	@Override public void preserialize() {}
	
	public ConfigurationSoundsBean getSounds() {
		return this.sounds;
	}
	
	public ConfigurationGraphicsBean getGraphics() {
		return this.graphics;
	}
}
